﻿using System;
using System.Linq;

namespace OpenWaves.ActivityFeed
{
    public static class UpdateExtensions
    {
        public static IQueryable<Update> GetPage(this IQueryable<Update> query, DateTime? publishedAfter, int pageSize)
        {
            if (publishedAfter.HasValue)
                query = query.Where(update => update.PublishedOn < publishedAfter);

            return query.Take(pageSize);
        }

        public static IQueryable<Update> PublishedWithinTimeRange(this IQueryable<Update> query, DateTime from, DateTime to)
        {
            return query.Where(update => update.PublishedOn >= from && update.PublishedOn <= to);
        }     
    }
}
